package com.ylsf.blog.service.impl;

import com.ylsf.blog.mapper.ArticleMapper;
import com.ylsf.blog.pojo.Article;
import com.ylsf.blog.service.UpdateService;
import com.ylsf.blog.utils.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

/**
 * 更新服务实现类
 */
public class UpdateServiceImpl implements UpdateService {

    @Override
    public boolean updateArticle(Article article) {
        boolean flag=false;
        SqlSession sqlSession = SqlSessionUtil.openSession();
        ArticleMapper articleMapper = sqlSession.getMapper(ArticleMapper.class);
        try {
            Integer integer = articleMapper.updateArticle(article);
            if(integer!=0){
                flag=true;
            }
            sqlSession.commit();
        }
        catch (Exception e) {
            if (sqlSession != null) {
                sqlSession.rollback(); // 在catch块中进行回滚操作
            }
        }finally {
            if (sqlSession != null) {
                SqlSessionUtil.close(sqlSession); // 在finally块中关闭SqlSession
            }
        }
        return true;
    }
}
